//
//  CustomAnnotationView.m
//  busRoute
//
//  Created by 物恋网 on 16/11/15.
//  Copyright © 2016年 wlw. All rights reserved.
//

#import "CustomAnnotationView.h"
@interface CustomAnnotationView()
@property (nonatomic, strong, readwrite) CustomCalloutView *calloutView;
@end
@implementation CustomAnnotationView


#define kCalloutWidth       100.0
#define kCalloutHeight      50.0

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    if (self.selected == selected)
    {
        return;
    }
    
    if (selected)
    {
        if (self.calloutView == nil)
        {
            self.calloutView = [[CustomCalloutView alloc] initWithFrame:CGRectMake(0, 0, kCalloutWidth, kCalloutHeight)];
            self.calloutView.center = CGPointMake(CGRectGetWidth(self.bounds) / 2.f + self.calloutOffset.x,
                                                  -CGRectGetHeight(self.calloutView.bounds) / 2.f + self.calloutOffset.y);
        }
        self.calloutView.subtitle = self.annotation.subtitle;
        
        [self addSubview:self.calloutView];
        if (_busSelectedBlock) {
            _busSelectedBlock(self.annotation);
        }
    }
    else
    {
        [self.calloutView removeFromSuperview];
    }
    
    [super setSelected:selected animated:animated];
}

-(void)setBusSelectedBlock:(BusSelectd)busSelectedBlock
{
    if (busSelectedBlock) {
        _busSelectedBlock = nil;
        _busSelectedBlock = busSelectedBlock;
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
